package com.ruoyi.service.jpjs.bi_plan.impl;

import com.ruoyi.mapper.jpjs.bi_plan.PlanMapper;
import com.ruoyi.service.jpjs.bi_plan.PlanService;
import com.ruoyi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class PlanServiceImpl implements PlanService {

    @Autowired
    private PlanMapper planMapper;

    @Override
    public List<Map<String, Object>> selectPlanList(Map<String, Object> map) {
        return planMapper.selectPlanList(map);
    }

    @Override
    public List<Map<String, Object>> selectPlan(String proName) {
        return planMapper.selectPlan(proName);
    }

    @Override
    public int addPlan(Map<String, String> map) {
        List<String> attributes = new ArrayList<>();
        attributes.add("compName");
        attributes.add("proName");
        attributes.add("years");
        attributes.add("months");
        attributes.add("planOutputValue");
        attributes.add("realityOutputValue");
        attributes.add("planBackPay");
        attributes.add("realityBackPay");
        List<Map<String, Object>> list = StringUtil.MainSubTableToList("con", attributes, map);
        int count = 0;
        for (Map<String, Object> map1 : list) {
            count += "".equals(map1.get("compName")) ? 0 : planMapper.addPlan(map1);
        }
        return count;
    }

    @Override
    public int editPlan(Map<String, String> map) {
        List<String> attributes = new ArrayList<>();
        attributes.add("id");
        attributes.add("compName");
        attributes.add("proName");
        attributes.add("years");
        attributes.add("months");
        attributes.add("planOutputValue");
        attributes.add("realityOutputValue");
        attributes.add("planBackPay");
        attributes.add("realityBackPay");
        List<Map<String, Object>> list = StringUtil.MainSubTableToList("con", attributes, map);
        int count = 0;
        for (Map<String, Object> map1 : list) {
            count += planMapper.editPlan(map1);
        }
        return count;
    }

    @Override
    public int deletePlan(String id) {
        String[] ids = id.split(",");
        return planMapper.deletePlan(ids);
    }

    @Override
    public int uniquen(Map<String, Object> map) {
        return planMapper.uniquen(map);
    }

    @Override
    public List<Map<String, Object>> selectPlanBackPayList(Map<String, Object> map) {
        return planMapper.selectPlanBackPayList(map);
    }

    @Override
    public List<Map<String, Object>> selectPlanBackPay(String compId) {
        return planMapper.selectPlanBackPay(compId);
    }

    @Override
    public int addPlanBackPay(Map<String, String> map) {
        List<String> attributes = new ArrayList<>();
        attributes.add("compId");
        attributes.add("years");
        attributes.add("months");
        attributes.add("planBackPay");
        attributes.add("realityBackPayIn");
        attributes.add("realityBackPayOut");
        attributes.add("realityBackPayTotal");
        List<Map<String, Object>> list = StringUtil.MainSubTableToList("con", attributes, map);
        int count = 0;
        for (Map<String, Object> map1 : list) {
            count += "".equals(map1.get("compName")) ? 0 : planMapper.addPlanBackPay(map1);
        }
        return count;
    }

    @Override
    public int editPlanBackPay(Map<String, String> map) {
        List<String> attributes = new ArrayList<>();
        attributes.add("id");
        attributes.add("compId");
        attributes.add("years");
        attributes.add("months");
        attributes.add("planBackPay");
        attributes.add("realityBackPayIn");
        attributes.add("realityBackPayOut");
        attributes.add("realityBackPayTotal");
        List<Map<String, Object>> list = StringUtil.MainSubTableToList("con", attributes, map);
        int count = 0;
        for (Map<String, Object> map1 : list) {
            count += planMapper.editPlanBackPay(map1);
        }
        return count;
    }

    @Override
    public int deletePlanBackPay(String id) {
        String[] ids = id.split(",");
        return planMapper.deletePlanBackPay(ids);
    }

    @Override
    public int uniquenBackPay(Map<String, Object> map) {
        return planMapper.uniquenBackPay(map);
    }
}
